package com.dasberg.gwt.server;

import com.dasberg.gwt.client.DispatcherService;
import com.dasberg.gwt.command.Action;
import com.dasberg.gwt.command.Result;
import com.dasberg.gwt.dispatch.ActionException;
import com.dasberg.gwt.dispatch.Dispatcher;
import com.dasberg.gwt.dispatch.HandlerException;
import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.inject.Inject;
import org.apache.log4j.Logger;

/**
 * The Actual Dispatcher implementation.
 * @author mischa
 */
public class DispatcherAdapter extends RemoteServiceServlet implements DispatcherService {
    private static final Logger LOG = Logger.getLogger(DispatcherAdapter.class);

    @Inject
    private Dispatcher dispatcher;

    public DispatcherAdapter() {
    }

    public Result process(Action action) throws SerializationException {
        try {
            return dispatcher.process(action);
        } catch (HandlerException e) {
            throw new RuntimeException(e);
        } catch (ActionException e) {
            throw new RuntimeException(e);
        }
    }
}